package cn.com.klun.tjy.service.impl;

import cn.com.klun.tjy.common.constant.ComConsts;
import cn.com.klun.tjy.dao.entity.TblStockDayInfos;
import cn.com.klun.tjy.dao.mapper.ser.TblStockDayInfosSerMapper;
import cn.com.klun.tjy.dubbo.bean.TjyParametersVo;
import cn.com.klun.tjy.service.MainOrderEffectService;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author whm
 * @ClassName AccountingServiceImpl
 * @Description 平台统一记账接口
 * @date 2017年11月02日 10:39
 */
@Service
public class MainOrderEffectServiceImpl implements MainOrderEffectService {
	
	private Logger logger = LoggerFactory.getLogger("AccountingServiceImpl");

	@Autowired
	private TblStockDayInfosSerMapper tblStockDayInfosSerMapper;

	@Override
	public TjyParametersVo service(TjyParametersVo vo) {
		 String logkey = vo.getLogAndKey();
	        try {
	        	// 查询策略要素信息

				// 获取 主力所占比例的阈值
//				String stockCode = vo.getString("stockCode");
//				String mainPercent = vo.getString("mainPercent");
//				String direction = vo.getString("direction");
//				String turnRate = vo.getString("turnRate");

				String mainPercent = "60";
				String turnRate = "4";
				String direction = "0";

				// 参数校验
				if(StringUtils.isEmpty(mainPercent)){
					vo.setResCode(ComConsts.resultEum.FAIL);
					vo.setResDesc("传递参数mainPercent为空");
				}
				if(StringUtils.isEmpty(turnRate)){
					vo.setResCode(ComConsts.resultEum.FAIL);
					vo.setResDesc("传递参数 turnRate 为空");
				}

				if("1".equals(direction)){
					mainPercent = "-"+mainPercent;
				}
				TblStockDayInfos tblStockDayInfos = new TblStockDayInfos();
				tblStockDayInfos.setTurnRate(new BigDecimal(turnRate));//换手率 小于 4
				tblStockDayInfos.setTurnRate(new BigDecimal(turnRate));//换手率 小于 4

				// 未涨停（可买）实时数据时效性留一周即可
				List<TblStockDayInfos> tblStockDayInfosList = tblStockDayInfosSerMapper.queryAccordStockList(tblStockDayInfos);
				// 整体查出的信息返回给 VO
				vo.setInfo("data",tblStockDayInfosList);
/*				int stockSize = tblStockDayInfosList.size();
				for (int i = 0; i < stockSize; i++) {
					TblStockDayInfos stockDayInfo =tblStockDayInfosList.get(i);
					// 返回每只股票的诊断信息
					TjyParametersVo tjyParametersVo = new TjyParametersVo();
					tjyParametersVo.setLogAndKey(vo.getLogAndKey());
					tjyParametersVo.setInfo("stockDayInfo",stockDayInfo);
					vo.setInfo("stockDayInfo",stockDayInfo);
					diagnoseStockLogic.exec(tjyParametersVo);

				}*/
	        }catch (Exception e) {
	            vo.setResDesc(e.getMessage());
	            logger.error("[MainOrderEffectServiceImpl][service]出现程序,日志关联key:{},异常：{}", logkey);
	        }
	        return vo;
	}

}
